import { reqGoodsInfo } from "@/api"

export default {
  state: {
    goodsInfo: {},
  },
  mutations: {
    UPDATE_GOODSINFO(state, goodsInfo) {
      state.goodsInfo = goodsInfo
    },
  },
  actions: {
    async getGoodsInfo({ commit }, searchParams) {
      const result = await reqGoodsInfo(searchParams)
      if (result.code == 200) {
        commit("UPDATE_GOODSINFO", result.data)
      }
    },
  },
  getters: {
    goodsList(state) {
      //  || []  的目的  数据还没有回来的时候 防止组件中使用报错(goodList[0])
      return state.goodsInfo.goodsList || []
    },
    trademarkList(state) {
      return state.goodsInfo.trademarkList || []
    },
    attrsList(state) {
      return state.goodsInfo.attrsList || []
    },
  },
}
